package com.copm.ifm.common.generate.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.copm.ifm.common.generate.util.YmlUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * MyDataSourceConfig
 *
 * @author Achin
 * @create 2019-01-11 11:33
 */
public class GeneratorConfig {

    //    static Properties prop = new Properties();
//    static {
//        try {
//            prop.load(GeneratorConfig.class.getClassLoader().getResourceAsStream("application-dev.yml"));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
    static Map<String, String> ymlConfig = new HashMap<>();

    static {
        ymlConfig = YmlUtil.getYmlConfig("/application.yml");
    }


    private GeneratorConfig() {
    }


    public GeneratorConfig(String includeTable, String moduleName) {
        this(includeTable, moduleName, null);
    }

    //将数据库表设置为必填项

    /**
     * @param includeTable 表名
     * @param moduleName   模块名
     * @param functionName 功能名
     */
    public GeneratorConfig(String includeTable, String moduleName, String functionName) {
        String tempPath = (functionName != null ? "/" + functionName : "");
        String tempPackage = (functionName != null ? "." + functionName : "");
        this.moduleName = moduleName;
        this.includeTable = includeTable;
        this.mapperPackage = moduleName + ".mapper" + tempPackage;
        this.servicePackage = moduleName + ".service" + tempPackage;
        this.serviceImplPackage = moduleName + ".service.impl" + tempPackage;
        this.controllerPackage = moduleName + ".controller" + tempPackage;
        this.entityPackage = moduleName + ".entity" + tempPackage;
        this.mapperXmlPath = "/ifm-servers/ifm-servers-" + moduleName + "/ifm-servers-" + moduleName + "-service/src/main/resources/mapper" + tempPath;
        this.mapperPath = "/ifm-servers/ifm-servers-" + moduleName + "/ifm-servers-" + moduleName + "-service/src/main/java/com/copm/ifm/servers/" + moduleName + "/mapper" + tempPath;
        this.servicePath = "/ifm-servers/ifm-servers-" + moduleName + "/ifm-servers-" + moduleName + "-service/src/main/java/com/copm/ifm/servers/" + moduleName + "/service" + tempPath;
        this.serviceImplPath = "/ifm-servers/ifm-servers-" + moduleName + "/ifm-servers-" + moduleName + "-service/src/main/java/com/copm/ifm/servers/" + moduleName + "/service/impl" + tempPath;
        this.controllerPath = "/ifm-servers/ifm-servers-" + moduleName + "/ifm-servers-" + moduleName + "-service/src/main/java/com/copm/ifm/servers/" + moduleName + "/controller" + tempPath;
        this.entityPath = "/ifm-servers/ifm-servers-" + moduleName + "/ifm-servers-" + moduleName + "-api/src/main/java/com/copm/ifm/servers/" + moduleName + "/entity" + tempPath;

    }

    //作者
    private String author = "system";


    //数据库配置
    private DbType dbType = DbType.MYSQL;
    private String url = ymlConfig.get("spring.datasource.url");
    private String driverName = ymlConfig.get("spring.datasource.driver-class-name");
    private String username = ymlConfig.get("spring.datasource.username");
    private String password = ymlConfig.get("spring.datasource.password");


    //表名[可配置pub_* 则会将所有pub开头的表生成相应的文件]
    private String includeTable = ""; //必填值


    //模块名
    private String moduleName;
    //父包名
    private String parent = "com.copm.ifm.servers"; //会自动补充mapper/service/service.impl/controller/entity
    //自定义生成文件的包名
    private String mapperPackage;
    private String servicePackage;
    private String serviceImplPackage;
    private String controllerPackage;
    private String entityPackage;


    //自定义输出文件位置
    //D:\workspace\idea\CrmDataSource/src/main/resources/mapper/pub/AccountService.java
    private String mapperXmlPath;
    private String mapperPath;
    private String servicePath;
    private String serviceImplPath;
    private String controllerPath;
    private String entityPath;

    //指定是否生成相应的文件类型
    private Boolean mapperXml = false;//默认不生成.xml文件
    private Boolean mapper = true;
    private Boolean service = true;
    private Boolean serviceImpl = true;
    private Boolean controller = false; //默认不生成controller文件
    private Boolean entity = true;

    public String getAuthor() {
        return author;
    }

    public GeneratorConfig setAuthor(String author) {
        this.author = author;
        return this;
    }

    public DbType getDbType() {
        return dbType;
    }

    public GeneratorConfig setDbType(DbType dbType) {
        this.dbType = dbType;
        return this;
    }

    public String getUrl() {
        return url;
    }

    public GeneratorConfig setUrl(String url) {
        this.url = url;
        return this;
    }

    public String getDriverName() {
        return driverName;
    }

    public GeneratorConfig setDriverName(String driverName) {
        this.driverName = driverName;
        return this;
    }

    public String getUsername() {
        return username;
    }

    public GeneratorConfig setUsername(String username) {
        this.username = username;
        return this;
    }

    public String getPassword() {
        return password;
    }

    public GeneratorConfig setPassword(String password) {
        this.password = password;
        return this;
    }

    public String getIncludeTable() {
        return includeTable;
    }

    public GeneratorConfig setIncludeTable(String includeTable) {
        this.includeTable = includeTable;
        return this;
    }

    public String getModuleName() {
        return moduleName;
    }

    public GeneratorConfig setModuleName(String moduleName) {
        this.moduleName = moduleName;
        return this;
    }

    public String getParent() {
        return parent;
    }

    public GeneratorConfig setParent(String parent) {
        this.parent = parent;
        return this;
    }

    public String getMapperPackage() {
        return mapperPackage;
    }

    public GeneratorConfig setMapperPackage(String mapperPackage) {
        this.mapperPackage = mapperPackage;
        return this;
    }

    public String getServicePackage() {
        return servicePackage;
    }

    public GeneratorConfig setServicePackage(String servicePackage) {
        this.servicePackage = servicePackage;
        return this;
    }

    public String getServiceImplPackage() {
        return serviceImplPackage;
    }

    public GeneratorConfig setServiceImplPackage(String serviceImplPackage) {
        this.serviceImplPackage = serviceImplPackage;
        return this;
    }

    public String getControllerPackage() {
        return controllerPackage;
    }

    public GeneratorConfig setControllerPackage(String controllerPackage) {
        this.controllerPackage = controllerPackage;
        return this;
    }

    public String getEntityPackage() {
        return entityPackage;
    }

    public GeneratorConfig setEntityPackage(String entityPackage) {
        this.entityPackage = entityPackage;
        return this;
    }

    public String getMapperXmlPath() {
        return mapperXmlPath;
    }

    public GeneratorConfig setMapperXmlPath(String mapperXmlPath) {
        this.mapperXmlPath = mapperXmlPath;
        return this;
    }

    public String getMapperPath() {
        return mapperPath;
    }

    public GeneratorConfig setMapperPath(String mapperPath) {
        this.mapperPath = mapperPath;
        return this;
    }

    public String getServicePath() {
        return servicePath;
    }

    public GeneratorConfig setServicePath(String servicePath) {
        this.servicePath = servicePath;
        return this;
    }

    public String getServiceImplPath() {
        return serviceImplPath;
    }

    public GeneratorConfig setServiceImplPath(String serviceImplPath) {
        this.serviceImplPath = serviceImplPath;
        return this;
    }

    public String getControllerPath() {
        return controllerPath;
    }

    public GeneratorConfig setControllerPath(String controllerPath) {
        this.controllerPath = controllerPath;
        return this;
    }

    public String getEntityPath() {
        return entityPath;
    }

    public GeneratorConfig setEntityPath(String entityPath) {
        this.entityPath = entityPath;
        return this;
    }

    public Boolean getMapperXml() {
        return mapperXml;
    }

    public GeneratorConfig setMapperXml(Boolean mapperXml) {
        this.mapperXml = mapperXml;
        return this;
    }

    public Boolean getMapper() {
        return mapper;
    }

    public GeneratorConfig setMapper(Boolean mapper) {
        this.mapper = mapper;
        return this;
    }

    public Boolean getService() {
        return service;
    }

    public GeneratorConfig setService(Boolean service) {
        this.service = service;
        return this;
    }

    public Boolean getServiceImpl() {
        return serviceImpl;
    }

    public GeneratorConfig setServiceImpl(Boolean serviceImpl) {
        this.serviceImpl = serviceImpl;
        return this;
    }

    public Boolean getController() {
        return controller;
    }

    public GeneratorConfig setController(Boolean controller) {
        this.controller = controller;
        return this;
    }

    public Boolean getEntity() {
        return entity;
    }

    public GeneratorConfig setEntity(Boolean entity) {
        this.entity = entity;
        return this;
    }
}
